package summer.codegenerator.model.base;

import java.io.Serializable;
import java.util.List;

import summer.codegenerator.model.enumeration.NodeType;

/**
 * 树节点模型
 * 
 * @author 蒋振
 * @since 2019年7月2日 下午2:33:37
 */
public class Node implements Serializable {

	private static final long serialVersionUID = 1L;

	// 节点类型
	private NodeType nodeType;

	// 节点数据
	private NodeData nodeData;

	// 节点名称
	private String nodeDataName;

	// 子节点
	private List<Node> children;

	public Node() {
	}

	public Node(NodeType type, NodeData data) {
		this.nodeType = type;
		this.nodeData = data;
		this.nodeDataName = data.dataName();
	}

	public String getNodeKey() {
		if (this.nodeType != null && this.nodeData != null) {
			String nodeIdTemplate = "%d_%d";
			return String.format(nodeIdTemplate, this.nodeType.getIndex(), this.nodeData.dataId());
		}
		;
		return null;
	}

	public NodeType getNodeType() {
		return nodeType;
	}

	public void setNodeType(NodeType nodeType) {
		this.nodeType = nodeType;
	}

	public NodeData getNodeData() {
		return nodeData;
	}

	public void setNodeData(NodeData nodeData) {
		this.nodeData = nodeData;
	}

	public String getNodeDataName() {
		return nodeDataName;
	}

	public void setNodeDataName(String nodeDataName) {
		this.nodeDataName = nodeDataName;
	}

	public List<Node> getChildren() {
		return children;
	}

	public void setChildren(List<Node> children) {
		this.children = children;
	}
}
